MainMenu.prototype = new Sprite();
function MainMenu(){
    Sprite.apply(this);
    Menu.apply(this);
    const MARGIN = 10;
    
    this.bg = Game._game.bitmaps[Game.picturesPath+"base/mainmenu.jpg"];
    this.addChild(this.bg);
    
    
    //this.levelMenu = new LevelMenu();
    this.buttons = new Array();
    this.buttons["start"] =new Button("Začať hru");
    this.buttons["select"] = new Button("Vybrať level");
    this.buttons["share"] = new Button("Zdielať");
    this.buttons["exit"] = new Button("Poslať priateľom");
                
    this.functions = new Array();
    this.functions["start"] = function(e){
        Game._game.StartGame();
    }
                
    this.functions["select"] = function(e){
        while (Game._game.numChildren > 0)
            Game._game.removeChildAt(0);
        Game._game.addChild(Game._game.menus["LevelMenu"]);
        Game._game.selectLevelMode = true;
    }
                
    this.functions["share"] = function(e){
        FB.ui(
        {
            method: 'feed',
            name: 'Matfyz Game',
            link: 'https://apps.facebook.com/matfyzgame/',
            picture: 'fast-springs-7354.heroku.com/pictures/logo.gif',
            caption: "Hra Logic pre nadejných uchádzačov o štúdium na FMFI UK",
            description: "Zahraj sa túto super-hyper-truper hru!!!"
        },
        function(response) {
            if (response && response.post_id) {
                console.log('Post was published.');
            } else {
                console.log('Post was not published.');
            }
        }
        );
    }
                
    this.functions["exit"] = function(e){
        FB.ui({
            method: 'apprequests',
            message: 'Zahraj sa hru!'
        }, null);
    }
                
    const fromTop = 50;            
    var i = 0;
    var maxWidth = 0;
    
    for (var key in this.buttons) {
        if (key == "each")
            break;
        var count = 4;
        var height = this.buttons[key].height + MARGIN*(3/2);
        var baseY = MainContainerHeight/2 - (count*(height))/2;
        this.buttons[key].x = MainContainerWidth/2 - this.buttons[key].width/2;
        this.buttons[key].y = baseY + i*height + fromTop;            
        this.buttons[key].addEventListener(MouseEvent.CLICK,this.functions[key]);
        maxWidth = Math.max(maxWidth, this.buttons[key].width);
        i++;
    }
    
    for (var key in this.buttons) {
        if (key == "each")
            break;
        this.buttons[key].setWidth(maxWidth);
        this.addChild(this.buttons[key]);
    }
}